﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.App.Applications.Company;
using Traceability.App.Applications.Photos;
using Traceability.App.DTO;
using Traceability.Domain;
using Traceability.ErrorCode;

namespace Traceability.App.Controllers
{
    /// <summary>
    /// 公共服务-控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CommonController : ControllerBase
    {
        private readonly IMediator mediator;

        public CommonController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加公司信息
        /// </summary>
        /// <param name="request">公司参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddCompany(CompanyAddCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取公司信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<CompanyDto>> GetCompanyData([FromQuery]CompanyQueryCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 保存照片
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> SavePhotos(PhotosSaveCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取照片集合
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<PhotosDto>>> GetPhotosList([FromQuery]PhotosQueryCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取地址级联
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<AddressDto>>> GetAddress() 
        {
            AddressQueryCommand request = new AddressQueryCommand();
            return mediator.Send(request);
        }
    }
}
